今天主要是對 Docker image 的配置做討論,官方建議中需要符合以下項目
# 使用具體版本的image
FROM ubuntu:24.04
RUN apt-get update && \
apt-get install -y python3 python3-pip && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# 建立非 root 使用者
RUN useradd -r -u 1000 -m -s /bin/sh appuser
WORKDIR /app
COPY requirements.txt /app/
RUN pip3 install --no-cache-dir -r requirements.txt
# 設定適當的檔案權限
COPY --chown=appuser:appuser app.py test_app.py entrypoint.sh /app/
RUN chmod +x /app/entrypoint.sh
# 使用非 root 使用者
USER appuser
EXPOSE 5000
ENTRYPOINT ["/app/entrypoint.sh"]
CMD ["run"]
針對 image 檢查
sha512sum kube-apiserver
參考文件
https://kubernetes.io/docs/concepts/security/security-checklist/